module GT = Gtk_tools

let size (w: < misc : GObj.misc_ops;  .. > ) width : unit =
    w#misc#set_size_request ~width ~height:25 ()

let create_popup_window title =
  let window = GWindow.window ~title ~border_width:10 ~show:false () in
    ignore (window#event#connect#delete 
	      (fun _ -> window#misc#hide(); true));
    window

let make_popup_window title packing =
  let window = GWindow.window ~title ~border_width:10 ~show:false () in
  let show_btn = GButton.button ~label:(title^"...") ~packing () in
    ignore (show_btn#connect#clicked ~callback:window#show);
    ignore (window#event#connect#delete 
	      (fun _ -> window#misc#hide(); true));
    window
;;
let button_popup_window title =
  let window = GWindow.window ~title ~border_width:10 ~show:false () in
  let show_btn = GButton.button ~label:(title^"...") () in
    ignore (show_btn#connect#clicked ~callback:window#show);
    ignore (window#event#connect#delete 
	      (fun _ -> window#misc#hide(); true));
    show_btn, window

let make_hist_processing_frame title lst1 perform_process lst2 slice_process =
  let call_perform_process text = 
      let tf = List.find (fun (s,_) -> s = text) lst1 in
      perform_process tf in
  let p_1d = GT.hbox [] [GT.label "1d: " [];
        GT.combo_button "perform" (List.map fst lst1)
          [`Activate call_perform_process] 
  ] in
  let choices = GEdit.combo () in
  choices#set_popdown_strings (List.map fst lst2);
  let proj_entry = GEdit.entry ~text:"X" () in
  size proj_entry 25;
  let n_entry = GEdit.entry ~text:"10" () in
  size n_entry 25;
  let call_slice_process () =
      let tf = List.find (fun (s,_) -> s = choices#entry#text) lst2 in
      let n = int_of_string n_entry#text in
      let proj = Histo.parse_projection proj_entry#text in
      slice_process tf (proj,n)
  in
  List.iter (fun e -> ignore(
      e#connect#activate ~callback:call_slice_process))
      [n_entry;proj_entry;choices#entry];
  let p_2d = GT.hbox [] [ 
      GT.label "2d: process" [];
      n_entry#coerce;
      GT.label "slices over" [];
      proj_entry#coerce;
      GT.label "by func." [];
      choices#coerce;
      GT.button "perform" [`Pressed call_slice_process];
  ] in
  GT.frame title (GT.vbox [] [p_1d; p_2d])
;;
